//
// Phong fragment shader
//

varying vec3 l;
varying vec3 v;
varying vec3 n;
varying float texture;
uniform sampler2D map;
uniform sampler2D map1;
uniform sampler2D map2;
uniform sampler2D map3;
uniform int option;

void main (void)
{
    const vec4  diffColor = vec4 ( 1.0, 1.0, 1.0, 1.0 );
    const vec4  specColor = vec4 ( 1.0, 1.0, 1.0, 1.0 );
    const float specPower = 900.0;

    vec3 n2   = normalize ( n );
    vec3 l2   = normalize ( l );
    vec3 v2   = normalize ( v );
    vec3 r    = reflect ( -v2, n2 );
    vec4 diff = diffColor * max ( dot ( n2, l2 ), 0.2 );
    vec4 spec = specColor * pow ( max ( dot ( l2, r ), 0.0 ), specPower );

	//gl_TexCoord[0] = gl_MultiTexCoord0;

	vec3 tex;
	if(texture == 0.0) tex=texture2D(map, gl_TexCoord[0]).rgb;
	else if(texture > 0.0 && texture <= 1.0) tex=texture2D(map1, gl_TexCoord[0]).rgb;
	else if(texture > 1.0 && texture <= 2.0) tex=texture2D(map2, gl_TexCoord[0]).rgb;
	else tex=texture2D(map3, gl_TexCoord[0]).rgb;

    gl_FragColor = vec4(tex.r, tex.g, tex.b, 1)*(diff + spec);
    if(option == 1) {
    	gl_FragColor.xyz -= vec3(0.2,-0.2,0.2);
    }
    else if(option == 2) gl_FragColor.xyz -= vec3(-0.2,0.2,0.2);
}